package sword.T26;

import util.TreeNode;

/**
 * @Author: 18362
 * @Create: 2022-04-01 10:45:57 星期五
 */
class Solution {

    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (B == null || A == null)
            return false;
        boolean result = false;
        if (A.val == B.val)
            result = judge(A, B);
        return result || isSubStructure(A.left, B) || isSubStructure(A.right, B);
    }

    private boolean judge(TreeNode A, TreeNode B) {
        if (B == null)
            return true;
        if (A == null)
            return false;
        if (A.val != B.val)
            return false;
        return judge(A.left, B.left) && judge(A.right, B.right);
    }
}